package com.qf.web;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.pojo.AirPojo;
import com.qf.pojo.DistrictPojo;
import com.qf.service.AirService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.jws.WebParam;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class AriController {
    @Autowired
    AirService airService;

    //查询所有空气情况，有条件按条件查询
    @RequestMapping("hello")
    public String hello(){
        return "hello1";
    }
    @RequestMapping("findall")
    public String findAll(AirPojo airPojo,Model model) {
        PageHelper.startPage(airPojo.getPageNum(),airPojo.getPageSize());
        List<AirPojo> list = airService.findAll(airPojo);
        PageInfo<AirPojo> pageInfo = new PageInfo<>(list);
        model.addAttribute("list", list);
        model.addAttribute("pageInfo",pageInfo);
        return "index";
    }
    @RequestMapping("findall2")
    public String findAll2(AirPojo airPojo,Model model) {
        PageHelper.startPage(airPojo.getPageNum(),airPojo.getPageSize());
        List<AirPojo> list = airService.findAll(airPojo);
        PageInfo<AirPojo> pageInfo = new PageInfo<>(list);
        model.addAttribute("list", list);
        model.addAttribute("pageInfo",pageInfo);
        return "hello";
    }

    //跳转到添加页面
    @RequestMapping("jumpadd")
    public String jumpadd() {
        return "add";
    }

    //添加
    @RequestMapping("addair")
    public String addair(AirPojo airPojo) {
        airService.addair(airPojo);
        return "forward:findall";
    }

    /*  //跳转至更新页面
      public String jumpupdate(){
          return "update";
      }*/
    //通过id查询
    @RequestMapping("selectbydis")
    public String selectbydis(int id,Model model) {
        AirPojo airPojo = airService.selectBydis(id);
        model.addAttribute("air", airPojo);
        return "update";
    }

    //更新数据
    @RequestMapping("update")
    public String updateair(AirPojo airPojo) {
        airService.updateair(airPojo);
        return "forward:findall";
    }

    //根据id删除
    @RequestMapping("delete")
    public String deletebyid(int id) {
        airService.deleteair(id);
        return "forward:findall";
    }
   /* //通过区域查询
    public String selectbydisc(int district_id,Model model){
        List<AirPojo> list2=airService.slesctBYdisc(district_id);
        model.addAttribute("list",list2);
        return "";
    }*/
    //查询所有的区
   /* @RequestMapping("selectall")
    public String selectall(Model model) {
        List<DistrictPojo> list2 = airService.selectall();
        model.addAttribute("list2", list2);
        return "forward:findall";
    }*/
}
